var loading = '<center><br /><img src="/MCS-SMS/modpub/images/loading.gif"/><br /></center>';
var newwindow;
function mpopUp(URL) {
    if (newwindow){
        if (newwindow.closed) {
            newwindow= window.open(URL,'name','height=490,width=660,left=100,  top=100,resizable=1,scrollbars=1,toolbar=0,status=yes');
        }else {
            newwindow.focus();
        }
    }else{
        newwindow= window.open(URL,'name','height=490,width=660,left=100,  top=100,resizable=1,scrollbars=1,toolbar=0,status=yes');
        if (window.focus) {newwindow.focus()}
    }
}
function infopopUp(URL) {
    if (newwindow){
        if (newwindow.closed) {
            newwindow= window.open(URL,'name','height=700,width=15000,left=100,  top=100,resizable=1,scrollbars=1,toolbar=0,status=yes');
        }else {
            newwindow.focus();
        }
    }else{
        newwindow= window.open(URL,'name','height=700,width=15000,left=100,  top=100,resizable=1,scrollbars=1,toolbar=0,status=yes');
        if (window.focus) {newwindow.focus()}
    }
}

function npop(URL){
    if (newwindow) newwindow.close();
	newwindow= window.open(URL,'name','height=700,width=800,resizable=1,scrollbars=1,toolbar=0,status=yes');
}
function byID(id){
    return document.getElementById(id);
}
function validSearch(str){
	if ((str.length == 2) ||  (str.length == 5) || (str.length == 7) || (str.length == 0)) return true;
	return false;
}
function toF(d){
    if (d.innerHTML){
        var a = d.innerHTML.toFloat();
        return (a>-1) ? a : 0;
    }else if (d.value) {
        var a = d.value.toFloat();
        return (a>-1) ? a : 0;
    } 
    return 0;
}

function toI(d){
    if (d.innerHTML){
        var a = d.innerHTML.toInt();
        return (a>-1) ? a : 0;
    }else if (d.value) {
        var a = d.value.toInt();
        return (a>-1) ? a : 0;
    } 
    return 0;
}

function toPos(a){
	if (a.toFloat() > 0)
		return a;
	else
		return 0;
}
function ce(a){return document.createElement(a)}
function tn(a){return document.createTextNode(a)}

function show_tool(obj_name){
    var objName = byID(obj_name);

    if(objName.style.display == "none"){
      objName.style.display = "block";
      objName.style.visibility  = "visible";
    } else {
      objName.style.display = "none";
    }

}

function hide_t(ob1,ob2){
   byID(ob1).style.display = "none";
   if (byID(ob2)) { byID(ob2).style.display = "block"; }
}

function Json_eval(edata){
    try
    {
        $('mymsg').innerHTML = '';
        return Json.evaluate(edata);
    }
    catch(err)
    {
        //err.description
		if (err.stack.indexOf("username and password") > -1)
        document.location.reload()
        $('mymsg').innerHTML = err.stack
    }

}

function note(message)
{
    if (message) alert(message);
}

function mytable(data,head,extra)
{
    var myhtml = "<table class='adminlist'><thead><tr>";
    head.each(function(item,h){
		var tb = (item[2]) ? item[2] + "." : "";
        myhtml += "<th><a href=\"javascript: sort('"+ tb + item[0]+"')\" >"+item[1]+"</a></th>";
    })
    if (extra[0][0]) myhtml += "<th></th>";
    if (extra[1][0]) myhtml += "<th></th>";
    myhtml += "</tr></thead><tbody>"
    var cls  = ""

    data.each(function(val,idx){
        cls = (idx%2 == 0) ? "row0" : "row1";
        e  = " onMouseOver=\"\" "
        e += " onMouseOut=\"\" class='"+cls+"' "
		c = (extra[0][0]) ? 'onClick="'+extra[0][2]+'('+val[extra[0][1]]+');"' : "";
          myhtml += "<tr " + e + " "+ c +">";
          head.each(function(con){
			var cval = (val[con[0]]) ? val[con[0]] : "";
            myhtml += "<td>" + cval +"</td>";
          })

        //if (extra[0][0]) myhtml += '<td><a href="#" onclick="'+extra[0][2]+'('+val[extra[0][1]]+');"><img src="modpub/images/tick.png" alt="edit" border="0"></a></td>';
        if (extra[0][0]) myhtml += '<td><a href="#"><img src="modpub/images/tick.png" alt="edit" border="0"></a></td>';
        if (extra[1][0]) myhtml += '<td><a href="#" onclick="'+extra[1][2]+'('+val[extra[1][1]]+');"><img src="modpub/images/publish_x.png" alt="Delete" ></a></td>';
          myhtml += "</tr>";
    })
    myhtml += "</tbody></table>";
    return myhtml;
}
function mytable1(data,head,extra)
{
    var myhtml = "<table class='adminlist'><thead><tr>";
    myhtml += "<th></th>";
    head.each(function(item,h){
		var tb = (item[2]) ? item[2] + "." : "";
        myhtml += "<th><a href=\"javascript: sort('"+ tb + item[0]+"')\" >"+item[1]+"</a></th>";
    })
    if (extra[0][0]) myhtml += "<th></th>";
    if (extra[1][0]) myhtml += "<th></th>";
    myhtml += "</tr></thead><tbody>"
    var cls  = ""

    data.each(function(val,idx){
        cls = (idx%2 == 0) ? "" : "odd";
        e  = " onMouseOver=\"\" "
        e += " onMouseOut=\"\" class='"+cls+"' "
		c = (extra[0][0]) ? 'onClick="'+extra[0][2]+'('+val[extra[0][1]]+');"' : "";
          myhtml += "<tr " + e + ">";
          myhtml += "<td>";
        dis = "";
		myhtml += "<input type='checkbox' class='groupitems' "+dis+" value="+val[extra[0][1]]+" />";
		myhtml +="</td>";
          head.each(function(con){
			var cval = (val[con[0]]) ? val[con[0]] : "";
            myhtml += "<td>" + cval +"</td>";
          })

        if (extra[0][0]) myhtml += '<td><a href="#" onclick="'+extra[0][2]+'('+val[extra[0][1]]+');"><img src="modpub/images/tick.png" alt="edit" border="0"></a></td>';
        //if (extra[0][0]) myhtml += '<td><a href="#"><img src="modpub/images/tick.png" alt="edit" border="0"></a></td>';
        if (extra[1][0]) myhtml += '<td><a href="#" onclick="'+extra[1][2]+'('+val[extra[1][1]]+');"><img src="modpub/images/publish_x.png" alt="Delete" ></a></td>';
          myhtml += "</tr>";
    })
    myhtml += "</tbody></table>";
    return myhtml;
}

function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function AddToOptionList(data,OptionList, OptionValue, OptionText) {
   //ClearOptions(OptionList)
   data.each(function(val){
     OptionList[OptionList.length] = new Option(val[OptionText], val[OptionValue]);
   }
   )
}

function optionSelected(m1,id) {
   for (i=0; i<m1.length; i++) {
      if (m1[i].value == id) m1.options[i].selected = true;
   }

}

function optionText(m1){
   for (i=0; i<m1.length; i++) {
      if (m1.options[i].selected == true) return m1.options[i].text;
   }
}

